--用于还原数据
CREATE OR REPLACE PROCEDURE
RECOVER_DATA AUTHID CURRENT_USER
IS
  CURSOR C1 
  IS 
  SELECT 
    * 
  FROM USER_TABLES 
  WHERE TABLE_NAME IN ('PDS_DIRS_HISTORYLIST', 'PDS_PARTS_HISTORYLIST', 'PDS_DIRS_PARTS', 'PDS_PARTS_PART');
  V_SQL VARCHAR2(1000);

BEGIN
  FOR V_R IN C1
  LOOP
    EXECUTE IMMEDIATE 'TRUNCATE TABLE ' || V_R.TABLE_NAME;
    V_SQL := 'INSERT INTO ' || V_R.TABLE_NAME || ' SELECT * FROM ' || 'BAK_' || V_R.TABLE_NAME;
    EXECUTE IMMEDIATE V_SQL;
  END LOOP;

  EXECUTE IMMEDIATE 'TRUNCATE TABLE PDS_PARTS_FILES_T';

  INSERT INTO PDS_PARTS_FILES_T
  SELECT
    ROWID,
    TRIM(PARTNO), 
    TRIM(VER), 
    FILENAME, 
    LOWER(TRIM(FILETYPE)), 
    FILESIZE,
    EDITDATE, 
    PICID, 
    ISOLDVER, 
    SERIALNO, 
    TRIM(NOTE), 
    WIDTH, 
    HEIGHT,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
  FROM PDS_PARTS_FILES;

  EXECUTE IMMEDIATE 'TRUNCATE TABLE PDS_PARTS_PART_HISTORY_T';

  INSERT INTO PDS_PARTS_PART_HISTORY_T
  SELECT
    P.ROWID,
    P.*,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
  FROM PDS_PARTS_PART_HISTORY P;

  COMMIT;
  
END;